/**
 * 
 */
package com.cms.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cms.common.ResultMsg;
import com.cms.constant.CmsConstant;
import com.cms.pojo.Article;
import com.cms.pojo.vo.ArticleVo;
import com.cms.service.ArticleService;
import com.github.pagehelper.PageInfo;

/**
 * @author zhaoyan
 *
 * 2020年1月9日
 */
@RequestMapping("article")
@Controller
public class ArticleController {
	
	
	@Autowired
	private ArticleService articleService;
	
	
	@RequestMapping("findArticle")
	public String articleList(Model m,ArticleVo articleVo,@RequestParam(defaultValue = "1")Integer pageNum) {
		
		PageInfo<Article> articlePage = articleService.findArticle(articleVo,pageNum);
		
		m.addAttribute("articlePage", articlePage);
		
		return "show/articlelist";
	}

	
	@RequestMapping("getArticle")
	@ResponseBody
	public ResultMsg<Article> getArticle(Integer articleId) {
		Article article = articleService.getArticle(articleId);
		if(article == null) 
			return new ResultMsg<Article>(CmsConstant.ARTICLE_STATUS_FAILURE,CmsConstant.ARTICLE_MSG_ERROR , null);
		return new ResultMsg<Article>(CmsConstant.ARTICLE_STATUS_SUCCESS, null, article);
	}
	
	@RequestMapping("checkArticle")
	@ResponseBody
	public ResultMsg<String> checkArticle( Integer id, Integer status){
		
		Integer num = articleService.checkArticle(id,status);
		
		return new ResultMsg<String>(num, null, null);
		
	}
	@RequestMapping("setHot")
	@ResponseBody
	public ResultMsg<String> setHot( Integer id, Integer hot){
		
		Integer num = articleService.setHot(id,hot);
		
		return new ResultMsg<String>(num, null, null);
		
	}
	
	
}
